package select;
import java.util.*;

public class Select{
	static void Xs (Student a) {
		System.out.println("学生姓名"+a.name+"学生年龄"+a.age+"学生性别"+a.sex+"学生学号"+a.number);
	}
	static void Tt (Teacher a) {
		System.out.println("教师姓名"+a.name+"教师年龄"+a.age+"教师性别"+a.sex+"教师编号"+a.number);
		
	}
	static void Rtname (Class a) {
		System.out.println(a.mingcheng);
	}
	
	static int laoshi = -1;
	static int shijian  = 0;
	static int  didian =0;
	static String mingcheng ="无";
	public static Class[] cla = new Class[10] ;{
	    for (int i=0;i<10;i++) {
	    	Class temp = new Class(laoshi,shijian,didian,mingcheng);
	    	cla[i]= temp;
	    }
	    }
	
	static String name = "无";
	static String sex  = "无";
	static int  xueshengrenshu =0;
	static int age =0;
	public static Student[] stu = new Student[30] ;{
    for (int i=0;i<30;i++) {
    	Student temp = new Student(name,xueshengrenshu,sex,age);
    	stu[i]= temp;
    }
    }
	
	static String tname = "无";
	static String tsex  = "无";
	static int  trenshu =0;
	static int tage =0;
	public static Teacher[] tea = new Teacher[5] ;{
    for (int i=0;i<5;i++) {
    	Teacher temp = new Teacher(tname,trenshu,tsex,tage);
    	tea[i]= temp;
    }
    }
	
public static void main(String[]args){
	try(Scanner sc = new Scanner(System.in)){
    int xueshengrenshu;
    xueshengrenshu = 0;
    int laoshirenshu;
    laoshirenshu = 0;
    int kc=0;

	while (true) {
	int check ;
	System.out.println("----------------------------------------");
	System.out.println("欢迎来到选课系统");
    System.out.println("学生输入1，老师输入2");
    check = sc.nextInt();
    if (check == 1) {
    	System.out.println("----------------------------------------");
    	 System.out.println("新建学生输入0，现有学生输入学号");
    	    check = sc.nextInt();
    	    Boolean x;
     	    x=true;
     	    if (xueshengrenshu<check) {x=false;System.out.println("输入错误");}
    	    if (check ==0) {
    	    	xueshengrenshu ++;
    	        System.out.println("输入姓名");
    	        String name = sc.next();
    	        System.out.println("输入性别");
    	        String sex = sc.next();
    	        System.out.println("输入年龄");
    	        int age = sc.nextInt();
    	        Student temp = new Student(name,xueshengrenshu,sex,age);
                stu[xueshengrenshu-1] = temp;   
                check = xueshengrenshu ;             
    	    }

       	        while (x) {
       	        int celect;
       	        System.out.println("----------------------------------------");
       	        
                Xs(stu[check-1]) ;
                int temp =0;
                
                System.out.println("----------------------------------------");
                 for (int i=0;i<5;i++) {
                	 if (stu[check-1].c[i]==-1) {
                		 temp ++;
                	 }
                	 else {
                		 System.out.println((i+1)+".");
                		 System.out.println("名称：");
        				 Rtname(cla[stu[check-1].c[i]]);//输出选择课表
        				 System.out.println("编号："+stu[check-1].c[i]);
        				 System.out.println("授课教师："+tea[cla[stu[check-1].c[i]].laoshi-1].name);
        				 System.out.println("时间："+cla[stu[check-1].c[i]].shijian);
        				 System.out.println("地点："+cla[stu[check-1].c[i]].didian);
        				
                	 }
                 }
                 if (temp==4) {
            		 System.out.println("学生未选课");
            	 } else {System.out.println("以上为已选课程");}
                 System.out.println("----------------------------------------");
                 
                 System.out.println("输入0选课，输入1退课，输入其它数字退出");  
                 celect=sc.nextInt();
                 if (celect==0) {
                	 while (true) {
        			 int check1,temp1=5 ; //创建一个输入
        			 System.out.println("----------------------------------------");
        			 System.out.println("现有课程（空表示无课程):");
        			 for (int i=0;i<kc;i++) {
        				 if (cla[i].laoshi>-1) {
        					 System.out.println((i+1)+".");
        					 Rtname(cla[i]);
        				 }
                     }
        			 System.out.println("----------------------------------------");
        			 System.out.println("输入需要选的课程编号来选择课程，输入其它数来返回上一级");
        			 check1 = sc.nextInt();
        			 if (check1<kc+1 && check1>0) {
        			 for (int i=0;i<5;i++) {
        				temp1 = temp1-1;
        				if (stu[check-1].c[i]==-1) {stu[check-1].c[i]=check1-1;System.out.println("选课成功");temp1 = temp1+1;break;}
        			 }
        			 if (temp1==0) {System.out.println("可选课程数不足,如要继续选课，可做退课处理");break;}
                	 }else{break;}}
                 }
                 else if (celect==1) {
                	 while (true) {
                	 int check2;
                	 System.out.println("----------------------------------------");
                	 System.out.println("已选课程（空表示无课程):");
                	 for (int i=0;i<5;i++) {
                		 if (stu[check-1].c[i]>-1) {
                         System.out.println((i+1)+".");
        				 Rtname(cla[stu[check-1].c[i]]);
                		 }
                     }
                	 System.out.println("----------------------------------------");
                	 System.out.println("选择想要退选的课程输入1-5,返回上一级输入其它数字");
                	 check2=sc.nextInt();
                	 if(check2<6 && check2>0) {
                	 stu[check-1].c[check-1]=-1;System.out.println("退课成功");
                	 } else {break;}
                	 }
                 } else {break;}
        		 }
    	         
    	    	
       	       
    }
    else if (check==2) {
    	System.out.println("----------------------------------------");
    	 System.out.println("新建老师输入0，现有老师输入编号");
 	    check = sc.nextInt();
 	    Boolean x;
 	    x=true;
 	    if (laoshirenshu<check) {x=false;System.out.println("输入错误");}
 	    if (check ==0) {
 	    	laoshirenshu ++;
 	        System.out.println("输入姓名");
 	        String name = sc.next();
 	        System.out.println("输入性别");
 	        String sex = sc.next();
 	        System.out.println("输入年龄");
 	        int age = sc.nextInt();
 	        Teacher temp = new Teacher(name,laoshirenshu,sex,age);
             tea[laoshirenshu-1] = temp;   
            check=laoshirenshu;
 	    } 
 	    while (x) {
 	    int check3;
 	    System.out.println("----------------------------------------");
        Tt(tea[check-1]);
        if (tea[check-1].ct[0]>-1) {System.out.println("所授课程:"+cla[tea[check-1].ct[0]].mingcheng);}
        if (tea[check-1].ct[1]>-1) {System.out.println("所授课程:"+cla[tea[check-1].ct[1]].mingcheng);}
        System.out.println("----------------------------------------");
        if(tea[check-1].ct[0]>-1 && tea[check-1].ct[1]>-1) {break;}
        System.out.println("输入1添加课程，输入其它数返回上一级菜单");
        check3=sc.nextInt();
        if(check3==1) {
        	
        
        	if (tea[check-1].ct[1]>-1) {
        
        		System.out.println("----------------------------------------");
        	int laoshi = check;
        	System.out.println("输入时间");
 	        int shijian = sc.nextInt();
 	        System.out.println("输入地点");
	        int didian = sc.nextInt();
	        System.out.println("输入名称");
	        String mingcheng = sc.next();
        	    	Class temp = new Class(laoshi,shijian,didian,mingcheng);
        	    	kc++;
        	    	cla[kc-1]= temp;
        	    	tea[check-1].ct[0]=kc-1;
        	    	System.out.println("----------------------------------------");
        	}
        	else {
        		System.out.println("----------------------------------------");
        		int laoshi = check;
            	System.out.println("输入时间");
     	        int shijian = sc.nextInt();
     	        System.out.println("输入地点");
    	        int didian = sc.nextInt();
    	        System.out.println("输入名称");
    	        String mingcheng = sc.next();
            	    	Class temp = new Class(laoshi,shijian,didian,mingcheng);
            	    	kc++;
            	    	cla[kc-1]= temp;
            	    	
            	    	tea[check-1].ct[1]=kc-1;
            	    	System.out.println("----------------------------------------");
        	}
	
        }else {break;}
       
        
 	    }
    }else {System.out.println("输入错误");}
    }   
	}   
}
}
